import System.Random 

fermatFactor :: Integer -> [(Integer, Integer)]
fermatFactor n = fermatFactor' n $ ceiling $ sqrt $ fromIntegral n

fermatFactor' :: Integer -> Integer -> [(Integer,Integer)]
fermatFactor' n a
             | isSquare bsq = (a - b, a + b) : fermatFactor' n (a-1)
             | otherwise = fermatFactor' n (a-1)
               where bsq = a^2 - n
                     b = floor $ sqrt $ fromIntegral bsq

isSquare :: Integer -> Bool
isSquare n = (round . sqrt . fromIntegral $ n) ^ 2 == n

divisors n = [x | x <- [1..(round (sqrt (fromIntegral n)))], n `rem` x == 0]
isPrime n = not $ 0 `elem` (map (\x -> n `rem` x) [2..(n-1)])
answer n = zip divs (map isPrime divs)
           where divs = divisors n
